home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 June
/
ccd0605.iso
/
Software
/
Shareware
/
Programare
/
nativej
/
nativej-trial.exe
/
{app}
/
examples-source
/
Gui.java
< prev
next >
Wrap
Text File
|
2004-12-14
|
2KB
|
52 lines
package examples;
import java.awt.*;
import java.awt.event.*;
/**
* This is a sample Java program that runs in GUI mode.
*
* It has two common characteristics of a typical Java graphical app:
*
* 1. The main() thread configures and displays the main window, then exits.
* 2. System.exit() is called when the termination event is received.
*
* Unfortunately calling System.exit() has the side effect of shutting
* down the entire native app.
*
* Take a look at Gui2.java to find out how to avoid using System.exit()
* to terminate your GUI app.
*/
public class Gui
{
/**
* The main() thread configures and displays the main window, then exits.
*/
public static void main(String[] args) throws Exception
{
// Create the main window and components used by this app
Frame frame = new Frame("Gui");
String msg = "Hello World!";
if (args.length > 0) msg = "Hello " + args[0] + "!";
Label label = new Label(msg, Label.CENTER);
// Handle the exit event for the main window
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
// Position the components within the main window
frame.setLayout(new BorderLayout());
frame.add(label, BorderLayout.CENTER);
// Resize and show main window
frame.pack();
frame.setSize(320, 240);
frame.show();
}
}